package com.evaluation.kexingcp.psycho.evaluation.sys.config

import com.evaluation.kexingcp.psycho.evaluation.sys.utils.SpelFunctions
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.expression.EvaluationContext
import org.springframework.expression.spel.support.StandardEvaluationContext


@Configuration
open class SysConfig {

    @Bean
    open fun evaluationContext(): EvaluationContext {
        val context = StandardEvaluationContext()
        context.registerFunction("getIdx",
            SpelFunctions::class.java.getMethod("getIdx", BooleanArray::class.java, Int::class.java))

        context.registerFunction("floor",
            SpelFunctions::class.java.getMethod("floor", Double::class.java))

        context.registerFunction("max",
            SpelFunctions::class.java.getMethod("max", DoubleArray::class.java))

        context.registerFunction("getMax",
            SpelFunctions::class.java.getMethod("getMax",Int::class.java, DoubleArray::class.java))

        return context
    }
}